package org.kongqian.org.service.impl;

import org.kongqian.basic.utils.AjaxResult;
import org.kongqian.basic.utils.BaiduAuditUtils;
import org.kongqian.org.service.IBaiduAuditService;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import java.util.Map;

@Service
public class BaiduAuditServiceImpl implements IBaiduAuditService {
    @Override
    public AjaxResult baiduAudit(String text, String image, String video) {
        //默认返回成功
        AjaxResult result = AjaxResult.getResult();

        //创建一个StringBuild来拼接返回的错误信息
        StringBuilder stringBuilder = new StringBuilder();

        //判断各个参数时候为空，不为空就认证
        if (!StringUtils.isEmpty(text)){
            Map<String, Object> map = BaiduAuditUtils.TextCensor(text);
            Boolean success =(Boolean) map.get("success");
            String message =(String) map.get("message");
            //做失败的操作
            if (!success){
                result.setSuccess(false);
                stringBuilder.append(text+"："+message);
            }
        }

        if (!StringUtils.isEmpty(image)){
            Map<String, Object> map = BaiduAuditUtils.TextCensor(image);
            Boolean success =(Boolean) map.get("success");
            String message =(String) map.get("message");
            //做失败的操作
            if (!success){
                result.setSuccess(false);
                stringBuilder.append(text+"："+message);
            }
        }

        if (!StringUtils.isEmpty(video)){
            //@TODO
        }
       if (!ObjectUtils.isEmpty(stringBuilder)){
           result.setMessage(stringBuilder.toString());
       }
        return result;
    }
}
